using System.Collections.Generic;
using I2.Loc;
using UnityEngine;

public class LocalizeSwitchObj : MonoBehaviour
{
	private List<string> allLanguage = new List<string>();

	[SerializeField]
	public List<SwitchByLang> localizeObj = new List<SwitchByLang>();

	public int curNumLanguage = -1;

	private void Start()
	{
		SetCurrentLanguage();
	}

	public void SetCurrentLanguage()
	{
		curNumLanguage = -1;
		string currentLanguage = LocalizationManager.CurrentLanguage;
		for (int i = 0; i < localizeObj.Count; i++)
		{
			if (localizeObj[i].objSwitch != null && localizeObj[i].language == currentLanguage)
			{
				if (curNumLanguage == i)
				{
					return;
				}
				curNumLanguage = i;
				break;
			}
		}
		if (curNumLanguage < 0 || curNumLanguage >= localizeObj.Count)
		{
			return;
		}
		for (int j = 0; j < localizeObj.Count; j++)
		{
			if (localizeObj[j].objSwitch != null)
			{
				if (curNumLanguage == j)
				{
					localizeObj[j].objSwitch.SetActive(true);
				}
				else
				{
					localizeObj[j].objSwitch.SetActive(false);
				}
			}
		}
	}

	private void Update()
	{
		if (!Application.isPlaying)
		{
			allLanguage = LocalizationManager.GetAllLanguages();
			foreach (string item in allLanguage)
			{
				bool flag = false;
				foreach (SwitchByLang item2 in localizeObj)
				{
					if (item == item2.language)
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					SwitchByLang switchByLang = new SwitchByLang();
					switchByLang.language = item;
					localizeObj.Add(switchByLang);
				}
			}
			for (int i = 0; i < localizeObj.Count; i++)
			{
				if (string.IsNullOrEmpty(localizeObj[i].language))
				{
					localizeObj.RemoveAt(i);
					i--;
				}
			}
			SetCurrentLanguage();
		}
		else
		{
			SetCurrentLanguage();
		}
	}
}
